﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO_QLNS;
using BUS_QLNS;

namespace GUI_QLNS.GUI
{
    public partial class frmMain : Form
    {

        public frmMain()
        {
            InitializeComponent();
        }

        #region tabTrangChu

        private void frmMain_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'datasetAuthor.Author' table. You can move, or remove it, as needed.
            this.authorTableAdapter.Fill(this.datasetAuthor.Author);
            // TODO: This line of code loads data into the 'vinaBookDataSet.Genre' table. You can move, or remove it, as needed.
            this.genreTableAdapter.Fill(this.datasetGenre.Genre);
        }

        private void gvDanhMucSach_SelectionChanged(object sender, EventArgs e)
        {
            if (gvDanhMucSach.SelectedRows.Count > 0)
            {
                int cat = int.Parse(gvDanhMucSach.SelectedRows[0].Cells[0].Value.ToString());
                BookBUS _BUS = new BookBUS();
                List<BookDTO> ls = _BUS.GetBookByCategory(cat);

                flowLayoutPanel1.Controls.Clear();
                for (int i = 0; i < ls.Count; ++i)
                {
                    flowLayoutPanel1.Controls.Add(new ucBookPreview(ls[i]));
                }

            }
        }

        #endregion

        #region tabTimKiem
        private void btnSearch_Click(object sender, EventArgs e)
        {
            int CatID = -1;
            int AutID = -1;
            string BookName = txtSearchString.Text;

            if (cbox_Genre.Checked)
                CatID = (int)cbxTheLoai.SelectedValue;
            if (cbox_Author.Checked)
                AutID = (int)cbxTacGia.SelectedValue;

            BookBUS bb = new BookBUS();
            List<BookDTO> ls = bb.GetBookByAuthorAndCategory(BookName, CatID, AutID);

            flowLayoutPanel2.Controls.Clear();
            for (int i = 0; i < ls.Count; ++i)
            {
                flowLayoutPanel2.Controls.Add(new ucBookPreview(ls[i]));
            }
        }

        private void cbox_Genre_CheckedChanged(object sender, EventArgs e)
        {
            cbxTheLoai.Enabled = cbox_Genre.Checked;
        }

        private void cbox_Author_CheckedChanged(object sender, EventArgs e)
        {
            cbxTacGia.Enabled = cbox_Author.Checked;
        }
        #endregion





    }
}